<template>
  <div pb-10>
    <div v-for="(item, index) in result" :key="index">
      <tpl_goods v-if="item.type === 'goodsOnly'" :res="item" />
      <tpl_block v-if="item.type === 'whiteSpace'" :res="item" />
      <tpl_banner v-if="item.type === 'carousel'" :res="item" />
      <tpl_search v-if="item.type === 'search'" :res="item" />
      <tpl_menu v-if="item.type === 'menu'" :res="item" />
      <tpl_flex_one v-if="item.type === 'flexOne'" :res="item" />
      <tpl_left_one_right_two
        v-if="item.type === 'leftOneRightTwo'"
        :res="item"
      />
      <tpl_left_two_right_one
        v-if="item.type === 'leftTwoRightOne'"
        :res="item"
      />
      <tpl_flex_two v-if="item.type === 'flexTwo'" :res="item" />
      <tpl_flex_three v-if="item.type === 'flexThree'" :res="item" />
      <tpl_flex_five v-if="item.type === 'flexFive'" :res="item" />
      <tpl_flex_four v-if="item.type === 'flexFour'" :res="item" />
      <tpl_hot_zone v-if="item.type === 'flexHotArea'" :res="item" />
      <tpl_category_goods v-if="item.type === 'goodsCategory'" :res="item" />
      <tpl_card_banner
        v-if="item.type === 'carouselCard'"
        :res="item"
      ></tpl_card_banner>
      <tpl_article_list
        v-if="item.type === 'articleList'"
        :res="item"
      ></tpl_article_list>
    </div>
    <tabbar v-if="!props.mall"></tabbar>
  </div>
</template>

<script setup lang="ts">
import { onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
import { getTopicData, getFloorData } from '@/api/home'
import { getFloorDataNew } from '@/api/decoration'
import tpl_banner from '@/pages/v3-template/tpl_banner.vue' //轮播图
import tpl_block from '@/pages/v3-template/tpl_block.vue' //空白
import tpl_category_goods from '@/pages/v3-template/tpl_category_goods.vue'
import tpl_flex_five from '@/pages/v3-template/tpl_flex_five.vue'
import tpl_flex_four from '@/pages/v3-template/tpl_flex_four.vue'
import tpl_flex_one from '@/pages/v3-template/tpl_flex_one.vue' //图片
import tpl_flex_three from '@/pages/v3-template/tpl_flex_three.vue'
import tpl_flex_two from '@/pages/v3-template/tpl_flex_two.vue'
import tpl_goods from '@/pages/v3-template/tpl_goods.vue'
import tpl_hot_zone from '@/pages/v3-template/tpl_hot_zone.vue'
import tpl_left_one_right_two from '@/pages/v3-template/tpl_left_one_right_two.vue'
import tpl_left_two_right_one from '@/pages/v3-template/tpl_left_two_right_one.vue'
import tpl_menu from '@/pages/v3-template/tpl_menu.vue' //菜单
import tpl_search from '@/pages/v3-template/tpl_search.vue' //搜索栏
import tpl_card_banner from '@/pages/v3-template/tpl_card_banner.vue'
import tpl_article_list from '@/pages/v3-template/tpl_article_list.vue'
const result = ref<any>('')
const props = defineProps<{
  preview: boolean
  topic: any
  mall: boolean
}>()

// 获取微页面内容
async function fetchTopicData() {
  const res = await getTopicData(props.topic.id)
  if (res.data.success) {
    console.log(JSON.parse(res.data.result.pageData))
    let foolData = res.data.result.pageData
      ? JSON.parse(res.data.result.pageData)
      : ''
    if (foolData.version) {
      result.value = foolData.data
      console.log(result.value)
      // 说明是新版楼层装修的内容
    }
  }
}

async function init() {
  if (props.topic) {
    fetchTopicData()
  } else if (props.mall) {
    const res = await getFloorData()
    if (res.data.success) {
      let foolData = res.data.result.pageData
        ? JSON.parse(res.data.result.pageData)
        : ''
      if (foolData.version) {
        result.value = foolData.data
        console.log(result.value)
        // 说明是新版楼层装修的内容
      }
    }
  } else {
    const res = await getFloorDataNew()
    if (res.data.success) {
      let foolData = res.data.result.pageData
        ? JSON.parse(res.data.result.pageData)
        : ''
      result.value = foolData.data
      console.log(result.value)
    }
  }
}

onMounted(() => {
  init()
})

defineExpose({
  init
})
onShareAppMessage(() => {
  return {
    path: '/pages/index'
  }
})
onShareTimeline(() => {
  return {
    query: '1',
  };
});
</script>

<style scoped></style>
